home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / dev / misc / vahunz.lha / vahunz / source / ugly / ustring.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-19  |  3.3 KB  |  225 lines

  1. /*
  2.  * This source file is part of Vahunz,
  3.  * a tool to make source code un-/more legible.
  4.  *
  5.  *--------------------------------------------------------------------------
  6.  *
  7.  * Vahunz and the Ugly library are Copyright (C) 1998 by
  8.  * Thomas Aglassinger <agi@giga.or.at>
  9.  *
  10.  * All rights reserved.
  11.  *
  12.  * Refer to the manual for more information.
  13.  *
  14.  *--------------------------------------------------------------------------
  15.  *
  16.  * Ubiqx library is Copyright (C) 1991-1998 by
  17.  * Christopher R. Hertel <crh@ubiqx.mn.org>
  18.  *
  19.  * Ubiqx library is free software; you can redistribute it and/or
  20.  * modify it under the terms of the GNU Library General Public
  21.  * License as published by the Free Software Foundation; either
  22.  * version 2 of the License, or (at your option) any later version.
  23.  *
  24.  */
  25. #include <ctype.h>
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <errno.h>
  30. #include "utypes.h"
  31. #include "umemory.h"
  32. #define n7H
  33. #include "ustring.h"
  34. int n9B(STRPTR s)
  35. {
  36. size_t y4C = strlen(s);
  37. int ch = 0;
  38. if (y4C)
  39. {
  40. ch = s[y4C - 1];
  41. }
  42. else
  43. {
  44. ch = 0;
  45. }
  46. return ch;
  47. }
  48. STRPTR z5J(d9P j1R, STRPTR j5R, ULONG q6U)
  49. {
  50. STRPTR c4G = NULL;
  51. if (j1R)
  52. {
  53. #if c6K
  54. c4G = (STRPTR) n3V(strlen(j1R) + 1, j5R, q6U);
  55. #else
  56. c4G = (STRPTR) c8Y(strlen(j1R) + 1);
  57. #endif
  58. if (c4G) 
  59. strcpy(c4G, j1R); 
  60. }
  61. return (c4G); 
  62. }
  63. STRPTR c8W(STRPTR s)
  64. {
  65. STRPTR e4Mf = s;
  66. if (s)
  67. for (; *s != '\0'; s++)
  68. *s = toupper(*s);
  69. return e4Mf;
  70. }
  71. int x9D(d9P s1, d9P s2)
  72. {
  73. #define s6K 1
  74. #if !s6K
  75. int z3L; 
  76. #endif
  77. unsigned char c1, c2; 
  78. size_t i = 0; 
  79. do
  80. {
  81. c1 = toupper(s1[i]);
  82. c2 = toupper(s2[i]);
  83. i++;
  84. }
  85. while (c1 && c2 && (c1 == c2));
  86. #if s6K
  87. return (c2 - c1);
  88. #else
  89. if (c1 < c2)
  90. z3L = -1; 
  91. else if (c1 > c2)
  92. z3L = +1; 
  93. else
  94. z3L = 0; 
  95. return (z3L); 
  96. #endif
  97. }
  98. int k4G(d9P s1, d9P s2, size_t n)
  99. {
  100. int z3L; 
  101. unsigned char c1, c2; 
  102. size_t i = 0; 
  103. do
  104. {
  105. c1 = toupper(s1[i]);
  106. c2 = toupper(s2[i]);
  107. i++;
  108. }
  109. while (c1 && c2 && (c1 == c2) && (i < n));
  110. if (c1 < c2)
  111. z3L = -1; 
  112. else if (c1 > c2)
  113. z3L = +1; 
  114. else
  115. z3L = 0; 
  116. return (z3L); 
  117. }
  118. STRPTR x9H(d9P s1, d9P s2)
  119. {
  120. const char *c1;
  121. const char *c2;
  122. do
  123. {
  124. c1 = s1;
  125. c2 = s2;
  126. while (*c1 != '\0' && (toupper(c1[0]) == toupper(c2[0])))
  127. {
  128. c1++;
  129. c2++;
  130. }
  131. if (*c2 == '\0')
  132. {
  133. return (char *) s1;
  134. }
  135. }
  136. while (*s1++ != '\0');
  137. return NULL;
  138. }
  139. void p9Nq(STRPTR s, STRPTR j5R, ULONG q6U)
  140. {
  141. #if c6K
  142. u6K(s, j5R, q6U);
  143. #else
  144. l5D(s);
  145. #endif
  146. }
  147. void a8W(STRPTR * j1R, d9P c4G, STRPTR j5R, ULONG q6U)
  148. {
  149. #if c6K
  150. p9Nq(*j1R, j5R, q6U); 
  151. *j1R = z5J(c4G, j5R, q6U); 
  152. #else
  153. l5D(*j1R); 
  154. *j1R = e0O(c4G); 
  155. #endif
  156. }
  157. STRPTR w2Y(const char ch)
  158. {
  159. static char l1N[2]; 
  160. l1N[0] = ch;
  161. l1N[1] = '\0';
  162. return l1N;
  163. }
  164. STRPTR v9P(d9P str, d9P set)
  165. {
  166. size_t i;
  167. STRPTR result = NULL;
  168. if (str)
  169. {
  170. i = strlen(str) - 1;
  171. while ((i) && (strchr(set, str[i]) == NULL))
  172. i--;
  173. if (strchr(set, str[i]))
  174. result = (STRPTR) & (str[i]);
  175. }
  176. return result;
  177. }
  178. BOOL o0Mj(STRPTR s, LONG * num)
  179. {
  180. BOOL h5P = FALSE;
  181. errno = 0;
  182. *num = strtol(s, NULL, 10);
  183. if (errno == 0)
  184. {
  185. h5P = TRUE;
  186. }
  187. return h5P;
  188. }
  189. STRPTR q0Qx(LONG num)
  190. {
  191. static char q0Kd[10]; 
  192. STRPTR u0Ct = NULL;
  193. if (sprintf(q0Kd, "%d", (int) num))
  194. {
  195. u0Ct = q0Kd;
  196. }
  197. return u0Ct;
  198. }
  199. LONG r1N(STRPTR str, STRPTR set, char q0Qt, BYTE m2M)
  200. {
  201. STRPTR s = e0O(set);
  202. LONG y0O = 0;
  203. if (s)
  204. {
  205. STRPTR l7F = strtok(s, w2Y(q0Qt));
  206. LONG count = 1;
  207. while (!y0O && l7F)
  208. {
  209. if (m2M & k2S)
  210. {
  211. if (!x9D(str, l7F))
  212. y0O = count;
  213. }
  214. else if (!strcmp(str, l7F))
  215. y0O = count;
  216. count++;
  217. l7F = strtok(NULL, w2Y(q0Qt));
  218. }
  219. y8Mj(s);
  220. }
  221. else
  222. y0O = -1;
  223. return (y0O);
  224. }
  225.